package com.biqee.job;

import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.biqee.service.hao123.Hao123XmlParseService;
import com.biqee.util.EnvUtil;

public class Hao123StyleItemParseJob extends QuartzJobBean {
	private static final Logger logger = Logger.getLogger(Hao123StyleItemParseJob.class);
	
	private boolean isRunning = false;
	
	@Override
	protected void executeInternal(JobExecutionContext context)
			throws JobExecutionException {
		if(!EnvUtil.isTaskServer()) {
			logger.info("task not run because this server is not task server");
			return;
		}
		
		if(isRunning) {
			logger.info("skip parsing Hao123StyleItems because isRunning is true.");
			return;
		}

		logger.info("start of parsing juhuasuan ");
		isRunning = true;
		try {
			Hao123XmlParseService hao123XmlParseService = (Hao123XmlParseService)context.getJobDetail().getJobDataMap().get("hao123XmlParseService");
			hao123XmlParseService.parseAll();
		} catch (Exception ex) {
			logger.error("parse failed! ", ex);
		}

		logger.info("end of parsing Hao123StyleItems ");
		isRunning = false;
	}
	
}